package com.kyc.kycxkplaygame.util;

import android.content.Context;
import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/7/4.
 */

public class getTiliTimeUtils {

    public static int getTimeMin(Context context) {
        String oldtime = (String) SharedPreferencesUtils.getParam(context, "oldtime", "");
        long min = 0;
        if (!TextUtils.isEmpty(oldtime)) {
            String nowYMDHMSTime = TimeUtil.getNowYMDHMSTime();
            SimpleDateFormat CurrentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTime = null;
            Date endTime = null;
            try {
                startTime = CurrentTime.parse(oldtime);
                endTime = CurrentTime.parse(nowYMDHMSTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //判断是否大于5分钟
            min = ((endTime.getTime() - startTime.getTime()) / 1000) / 60;
        }
        return (int) min;
    }

    public static int getTimeSecond(Context context) {
        String oldtime = (String) SharedPreferencesUtils.getParam(context, "oldtime", "");
        long second = 0;
        if (!TextUtils.isEmpty(oldtime)) {
            String nowYMDHMSTime = TimeUtil.getNowYMDHMSTime();
            SimpleDateFormat CurrentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date startTime = null;
            Date endTime = null;
            try {
                startTime = CurrentTime.parse(oldtime);
                endTime = CurrentTime.parse(nowYMDHMSTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            //判断是否大于5分钟
            long min = ((endTime.getTime() - startTime.getTime()) / 1000) / 60;
            long countSecond = (endTime.getTime() - startTime.getTime()) / 1000;
            second = countSecond - (min * 60);
        }
        return (int) second;
    }
}
